import java.awt.Container;
import java.awt.EventQueue;

import javax.swing.JFrame;
import java.awt.CardLayout;
import javax.swing.JPanel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.LayoutStyle.ComponentPlacement;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


public class Demo {

	private JFrame frame;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Demo window = new Demo();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public Demo() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 450, 300);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(new CardLayout(0, 0));
		
		JPanel panel1 = new JPanel();
		frame.getContentPane().add(panel1, "panel1");
		
		JLabel lblPanelA = new JLabel("Panel A");
		
		
		JButton btnMovetoPanelB = new JButton("Move to Panel B");
		
		// This is when I double click the Move to Panel B button
		btnMovetoPanelB.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Container pnlContent = frame.getContentPane();
				CardLayout layout = (CardLayout)(pnlContent.getLayout());
				layout.show(pnlContent, "panel2");
	
				
				
			}
		});
		GroupLayout gl_panel1 = new GroupLayout(panel1);
		gl_panel1.setHorizontalGroup(
			gl_panel1.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel1.createSequentialGroup()
					.addGroup(gl_panel1.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panel1.createSequentialGroup()
							.addGap(136)
							.addComponent(lblPanelA))
						.addGroup(gl_panel1.createSequentialGroup()
							.addGap(14)
							.addComponent(btnMovetoPanelB)))
					.addContainerGap(268, Short.MAX_VALUE))
		);
		gl_panel1.setVerticalGroup(
			gl_panel1.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel1.createSequentialGroup()
					.addGap(22)
					.addComponent(lblPanelA)
					.addPreferredGap(ComponentPlacement.RELATED, 151, Short.MAX_VALUE)
					.addComponent(btnMovetoPanelB)
					.addGap(60))
		);
		panel1.setLayout(gl_panel1);
		
		JPanel panel2 = new JPanel();
		frame.getContentPane().add(panel2, "panel2");
		
		JLabel lblPanelB = new JLabel("Panel B");
		
		JButton btnMovetoPanelC = new JButton("Move to Panel C");
		GroupLayout gl_panel2 = new GroupLayout(panel2);
		gl_panel2.setHorizontalGroup(
			gl_panel2.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel2.createSequentialGroup()
					.addGroup(gl_panel2.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panel2.createSequentialGroup()
							.addGap(128)
							.addComponent(lblPanelB))
						.addGroup(gl_panel2.createSequentialGroup()
							.addGap(58)
							.addComponent(btnMovetoPanelC)))
					.addContainerGap(248, Short.MAX_VALUE))
		);
		gl_panel2.setVerticalGroup(
			gl_panel2.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel2.createSequentialGroup()
					.addGap(11)
					.addComponent(lblPanelB)
					.addPreferredGap(ComponentPlacement.RELATED, 165, Short.MAX_VALUE)
					.addComponent(btnMovetoPanelC)
					.addGap(57))
		);
		panel2.setLayout(gl_panel2);
		
		// This is when I double click Move to Panel C button
		btnMovetoPanelC.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
					Container pnlContent = frame.getContentPane();
					CardLayout layout = (CardLayout)(pnlContent.getLayout());
					layout.show(pnlContent, "panel3");
			
			}
			
			
			
		});
		
		JPanel panel3 = new JPanel();
		frame.getContentPane().add(panel3, "panel3");
		
		JLabel lblPanelC = new JLabel("Panel C");
		
		JButton btnMoveToPanelA = new JButton("Move to Panel A");
		
		// This is when I double click Move to Panel A button 
		btnMoveToPanelA.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				Container pnlContent = frame.getContentPane();
				CardLayout layout = (CardLayout)(pnlContent.getLayout());
				layout.show(pnlContent, "panel1");
				
			}
		});
		GroupLayout gl_panel3 = new GroupLayout(panel3);
		gl_panel3.setHorizontalGroup(
			gl_panel3.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel3.createSequentialGroup()
					.addGroup(gl_panel3.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panel3.createSequentialGroup()
							.addGap(174)
							.addComponent(lblPanelC))
						.addGroup(gl_panel3.createSequentialGroup()
							.addGap(34)
							.addComponent(btnMoveToPanelA)))
					.addContainerGap(230, Short.MAX_VALUE))
		);
		gl_panel3.setVerticalGroup(
			gl_panel3.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel3.createSequentialGroup()
					.addGap(18)
					.addComponent(lblPanelC)
					.addPreferredGap(ComponentPlacement.RELATED, 120, Short.MAX_VALUE)
					.addComponent(btnMoveToPanelA)
					.addGap(95))
		);
		panel3.setLayout(gl_panel3);
	}
}
